package com.cike.productmanager.DBHelper;

import java.util.ArrayList;
import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import android.util.Log;


public class StoreInfoContentHandler extends DefaultHandler {

	
		private static final String TAG = "XMLContentHandler";
		private List<StoreInfo> storeInfos;
		private StoreInfo storeInfo;
		private String preTag;
		
		
		public List<StoreInfo> getStoreInfos()
		{
			return storeInfos;
		}


		@Override
		public void characters(char[] ch, int start, int length)
				throws SAXException 
			{
			String data=null;
			if (storeInfo!=null)
			{
				if("id".equals(preTag))
				{
					data = new String(ch, start,length);
					storeInfo.setStoreCode(data);
				}
				else if("storename".equals(preTag))
				{
					data = new String(ch, start,length);
					storeInfo.setStoreName(data);
				}
				else if("type".equals(preTag))
				{
					data = new String(ch, start,length);
					storeInfo.setStoreType(data);
				}
				
				else if("khzb".equals(preTag))//�ͻ��ܲ���
				{
					data = new String(ch, start,length);
		            storeInfo.setCustomhq(data);
				}
				else if("customer".equals(preTag))//�ͻ����
				{
					data = new String(ch, start,length);
		            storeInfo.setCustomName(data);
				}
				else if("khmanager".equals(preTag))//�ͻ�����
				{
					data = new String(ch, start,length);
		            storeInfo.setCustomerMG(data);
				}
				else if("groupid".equals(preTag))
				{
					data = new String(ch, start,length);
		            storeInfo.setGroudId(data);
				}
				else if("imgpath".equals(preTag))//ͼƬ·��
				{
					data = new String(ch, start,length);
		          
				}
				else if("province".equals(preTag))
				{
					data = new String(ch, start,length);
		            storeInfo.setProvince(data);
				}
				else if("city".equals(preTag))
				{
					data = new String(ch, start,length);
		            storeInfo.setCity(data);
				}
				else if("qu".equals(preTag))
				{
					data = new String(ch, start,length);
					storeInfo.setErea(data);
				}
				else if("street".equals(preTag))
				{
					data = new String(ch, start,length);
		            storeInfo.setStreet(data);
				}
				else if("longla".equals(preTag))
				{
					data = new String(ch, start,length);
					storeInfo.setLW(data);
				}
				else if("mobile".equals(preTag))
				{
					data = new String(ch, start,length);
		            storeInfo.setPhone(data);
				}
				else if("tallyname".equals(preTag))
				{
					data = new String(ch, start,length);
		            storeInfo.setTallyman(data);
				}
				
				
			}
			Log.i(TAG, "�������ݣ�"+new String(ch, start,length));
			
		}


		@Override
		public void endDocument() throws SAXException {
			super.endDocument();
			Log.i(TAG, "�ĵ��������");
		}


		@Override
		public void endElement(String uri, String localName, String qName)
				throws SAXException {
			if ("store".equals(localName)&&storeInfo!=null)
			{
				storeInfos.add(storeInfo);
				storeInfo = null;
			}
			String tag=preTag;//TODO ����û�õģ�
			preTag = null;
			Log.i(TAG, localName + "�������");
			
		}


		@Override
		public void startDocument() throws SAXException {

			storeInfos = new ArrayList<StoreInfo>();
			Log.i(TAG, "��ʼ����...");
		}


		@Override
		public void startElement(String uri, String localName, String qName,
				Attributes attributes) throws SAXException {

			try {
				if ("store".equals(localName)) 
				{
					storeInfo = new StoreInfo();
//					report.setReportName(new String(attributes.getValue("reportName")));
				}

				preTag = localName;
				Log.i(TAG, "����Ԫ�أ�" + localName);
			} catch (Exception e)
			{
//				Util.Log(e.toString());
			}
		}

}
